package aom.ju.ss.utils.provinceCityDistrict

import android.app.Activity
import android.view.View
import android.widget.TextView
import aom.ju.ss.lpInterface.ListDialogCallBack
import aom.ju.ss.lpInterface.MyHttpCallBack
import aom.ju.ss.utils.http.LP_API
import aom.ju.ss.utils.http.OKHttpUtils
import aom.ju.ss.utils.show
import com.google.gson.Gson

interface streetIdCall {
    fun ok(street_id: String, street: String)
}

class StreetSelectionTool(activity: Activity, pid: String?, tvShow: TextView, call: streetIdCall) {

    init {
        tvShow.setOnClickListener(View.OnClickListener {
            if (pid == null || pid == "" || pid == "0") {
                "请先选择省市区".show
                return@OnClickListener
            }
            OKHttpUtils(activity)
                .SetApiUrl(LP_API.region_list_by_pid)
                .SetKey("pid")
                .SetValue(pid)
                .POST(object : MyHttpCallBack {
                    override fun ok(jsonString: String, httpTY: String) {
                        val mode = Gson().fromJson(jsonString, StreetMode::class.java)
                        ListDialog(activity, mode.data, object : ListDialogCallBack {
                            override fun ck(data: Any, p: Int) {
                                tvShow.text = (data as StreetInfo).name
                                call.ok(data.id.toString(), data.name)
                            }
                        })
                    }

                    override fun error(e: String?, jsonString: String?, httpTY: String?) {
                        e?.show()
                    }

                })
        })

    }
}


data class StreetMode(
    val count: Int,
    val `data`: List<StreetInfo>,
)

data class StreetInfo(
    val id: Int,
    val name: String
)

